<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<html>
<head>
    <title>注册</title>
    <!--引入elementui得样式-->
    <link type="text/css" rel="stylesheet" href="/css/index.css"/>
    <!--引入vue得依赖必须再elementui之前引入vue-->
    <script type="text/javascript" src="/js/vue.js"></script>
    <script type="text/javascript" src="/js/index.js"></script>
    <script type="text/javascript" src="/js/axios.min.js"></script>
    <script type="text/javascript" src="/js/qs.min.js"></script>
</head>
<body>
<div id="login">
    <div id="loginBox">
        <el-form :model="loginForm" status-icon :rules="loginRules" ref="ruleForm"  label-width="80px" class="demo-ruleForm" id="loginForm">
            <el-form-item label="账号:" prop="phoneNumber">
                <el-input type="text" v-model="loginForm.phoneNumber" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="密码:" prop="password">
                <el-input type="password" v-model="loginForm.password" autocomplete="off"></el-input>
            </el-form-item>
            <el-form-item label="昵称:" prop="realname">
                <el-input type="text" v-model="loginForm.realname" autocomplete="off"></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="login()">注册</el-button>
                <el-button type="primary" @click="login1()">已有账号,去登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</div>
</body>
<script>
    var app=new Vue({
        el:"#login",
        data:{
            //登录的表单对象
            loginForm:{},
            //登录的规则
            loginRules:{
                username:[
                    { required: true, message: '请输入账号', trigger: 'blur' },
                ],
                password:[
                    { required: true, message: '请输入密码', trigger: 'blur' },
                ]
            }
        },
        methods:{
            login(){
                this.$refs.ruleForm.validate((valid) => {
                    if(valid){
                        axios.post("/user/registration",this.loginForm).then(resp=>{
                            console.log(resp);
                            if(resp.data.code===200){
                                this.$message.success("注册成功");
                                location.href="/user.html";
                            }else{
                                this.$message.error("注册失败");
                            }
                        })
                    }
                })
            },
            login1(){
                location.href="/user.html";
            }
        }
    })
</script>

<style>
    #loginBox{
        width: 450px;
        height: 300px;
        margin: 200px auto;

    }

    #loginForm{
        margin: 20px auto;
    }
</style>
</html>